﻿using Mes.Application.DTO.Inputs.Quality;
using Mes.Application.DTO.Results.Quality;
using Mes.Domain.BoundedContext.Entities.Quality;
using Mes.Domain.BoundedContext;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Mes.Infrastructure.Data.BoundedContext.Repositories.MasterData;
using Mes.Infrastructure.Data.BoundedContext.Repositories.Quality;
using Microsoft.EntityFrameworkCore;

namespace Mes.Application.Services.Quality
{
    public class SpcRuleService: ISpcRuleService
    {
        private readonly IMapper _mapper;
        private readonly ISpcRuleRepository _SpcRuleRepository;
        public SpcRuleService(IMapper mapper, ISpcRuleRepository SpcRuleRepository)
        {
            if (mapper == null || SpcRuleRepository == null)
            {
                throw new ArgumentNullException();
            }
            _mapper = mapper;
            _SpcRuleRepository = SpcRuleRepository;
        }

        /// <summary>
        /// 查询Spc规则列表
        /// </summary>
        /// <returns></returns>
        public async Task<ItemsResult<SpcRuleResult>> GetSpcRulesAsync()
        {
            var rules = await _SpcRuleRepository.Query().OrderBy(x => x.Rule_Id).ToListAsync();
            var data = _mapper.Map<List<SpcRuleResult>>(rules);
            return new ItemsResult<SpcRuleResult> { Items= data };
        }
    }
}
